home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / dev / misc / intlist.lha / IntList / Source / IntList-3,14.asm < prev    next >
Encoding:
Assembly Source File  |  1997-11-08  |  15.0 KB  |  707 lines

  1. *******************************************************
  2. *
  3. ** IntList - a replacement for the original IntList V36
  4. ** by Commodore Amiga
  5. *
  6. ** This IntList has got extensions to the original one,
  7. ** it will display software interrupts and CIA resource
  8. ** interrupt vectors.
  9. *
  10. ** Written 08.11.1997 by Joerg van de Loo
  11. **             Hoevel 15
  12. **             47559 Kranenburg
  13. **             Germany
  14. *
  15.  
  16.     OUTPUT    RAM:IntList
  17.  
  18.  
  19.     STRUCTURE    _Table,68
  20.     APTR    _IRQ
  21.     APTR    _CIABBase
  22.     LABEL    _TableSize
  23.  
  24.     include    RAD:include/startup.easy
  25.  
  26.     OPT    P+    ; enable position independent code
  27. *    OPT    D+    ; enable debug informations for load-file
  28.  
  29. _main
  30.     bsr.w    _GetVBR
  31.     move.l    D0,_IRQ(A5)
  32.  
  33.     bsr.w    _PrintStatus
  34.  
  35.     bsr.s    _GetTBE
  36.     bsr.s    _GetDSKBLK
  37.     bsr.s    _GetSOFTINT
  38.     bsr.w    _GetCIAA
  39.     bsr.s    _GetCOP
  40.     bsr.s    _GetVERTB
  41.     bsr.w    _GetBLIT
  42.     bsr.w    _GetAUD0
  43.     bsr.w    _GetAUD1
  44.     bsr.w    _GetAUD2
  45.     bsr.w    _GetAUD3
  46.     bsr.w    _GetRBF
  47.     bsr.w    _GetDSKSYN
  48.     bsr.w    _GetCIAB
  49.     bsr.w    _GetSoftInts
  50.     bsr.w    _SetPatch
  51.     rts
  52.  
  53. _GetTBE
  54.     movea.l    _SysBase(A5),A6
  55.     lea    IVTBE(A6),A2
  56.     lea    _TBETxt(pc),A3
  57.     bsr.w    _GetIRQ
  58.     rts
  59. _GetDSKBLK
  60.     movea.l    _SysBase(A5),A6
  61.     lea    IVDSKBLK(A6),A2
  62.     lea    _DSKBLKTxt(pc),A3
  63.     bsr.w    _GetIRQ
  64.     rts
  65. _GetSOFTINT
  66.     movea.l    _SysBase(A5),A6
  67.     lea    IVSOFTINT(A6),A2
  68.     lea    _SOFTINTTxt(pc),A3
  69.     bsr.w    _GetIRQ
  70.     rts
  71. _GetCIAA
  72.     moveq    #0,D0
  73.     bsr.w    _GetCIAs
  74.     rts    
  75. _GetCOP
  76.     movea.l    _SysBase(A5),A6
  77.     lea    IVCOPER(A6),A2
  78.     lea    _COPTxt(pc),A3
  79.     bsr.w    _GetIRQ
  80.     rts
  81. _GetVERTB
  82.     movea.l    _SysBase(A5),A6
  83.     lea    IVVERTB(A6),A2
  84.     lea    _VERTBTxt(pc),A3
  85.     bsr.s    _GetIRQ
  86.     rts
  87. _GetBLIT
  88.     movea.l    _SysBase(A5),A6
  89.     lea    IVBLIT(A6),A2
  90.     lea    _BLITTxt(pc),A3
  91.     bsr.s    _GetIRQ
  92.     rts
  93. _GetAUD0
  94.     movea.l    _SysBase(A5),A6
  95.     lea    IVAUD0(A6),A2
  96.     lea    _AUD0Txt(pc),A3
  97.     bsr.s    _GetIRQ
  98.     rts
  99. _GetAUD1
  100.     movea.l    _SysBase(A5),A6
  101.     lea    IVAUD1(A6),A2
  102.     lea    _AUD1Txt(pc),A3
  103.     bsr.s    _GetIRQ
  104.     rts
  105. _GetAUD2
  106.     movea.l    _SysBase(A5),A6
  107.     lea    IVAUD2(A6),A2
  108.     lea    _AUD2Txt(pc),A3
  109.     bsr.s    _GetIRQ
  110.     rts
  111. _GetAUD3
  112.     movea.l    _SysBase(A5),A6
  113.     lea    IVAUD3(A6),A2
  114.     lea    _AUD3Txt(pc),A3
  115.     bsr.s    _GetIRQ
  116.     rts
  117. _GetRBF
  118.     movea.l    _SysBase(A5),A6
  119.     lea    IVRBF(A6),A2
  120.     lea    _RBFTxt(pc),A3
  121.     bsr.s    _GetIRQ
  122.     rts
  123. _GetDSKSYN
  124.     movea.l    _SysBase(A5),A6
  125.     lea    IVDSKSYNC(A6),A2
  126.     lea    _DSKSYNTxt(pc),A3
  127.     bsr.s    _GetIRQ
  128.     rts
  129. _GetCIAB
  130.     moveq    #1,D0
  131.     bsr.w    _GetCIAs
  132.     rts    
  133.  
  134. _GetIRQ    ; A2 exec server/handler list
  135.     tst.l    IV_NODE(A2)
  136.     beq.s    .server
  137.     movea.l    IV_NODE(A2),A2        ; IRQ Node
  138. .scanhandler
  139.     move.l    LN_NAME(A2),-(sp)
  140.     moveq    #0,D0
  141.     move.b    LN_PRI(A2),D0
  142.     ext.w    D0
  143.     move.l    D0,-(sp)
  144.     move.l    A3,-(sp)
  145.     bsr.w    _printf
  146.     lea    12(sp),sp
  147.  
  148.     move.l    (A2),D0            ; Next IRQ Node
  149.     beq.s    .done
  150.     movea.l    D0,A2
  151.     move.l    (A2),D0            ; If only last entry!
  152.     beq.s    .done
  153.     bra.s    .scanhandler
  154. *---------------------
  155. .server
  156.     move.l    (A2),D0            ; IV_DATA
  157.     beq.s    .done            ; Empty?
  158.     bmi.s    .done            ; Was opened, now removed?
  159.  
  160.     movea.l    D0,A2            ; Server (struct List;)
  161.     move.l    (A2),D0            ; First node
  162.     beq.s    .done
  163.     movea.l    D0,A2
  164. .scanserver
  165.     move.l    LN_NAME(A2),-(sp)
  166.     moveq    #0,D0
  167.     move.b    LN_PRI(A2),D0
  168.     ext.w    D0
  169.     move.l    D0,-(sp)
  170.     move.l    A3,-(sp)
  171.     bsr.w    _printf
  172.     lea    12(sp),sp
  173.     move.l    (A2),D0
  174.     beq.s    .done
  175.     movea.l    D0,A2
  176.     move.l    (A2),D0            ; If only last entry!
  177.     beq.s    .done
  178.     bra.s    .scanserver
  179. .done
  180.     rts
  181.  
  182. * -----------------------------
  183. * Special: CIAs...
  184.  
  185. _GetCIAs
  186.     movea.l    _SysBase(A5),A6
  187.     move.l    D0,D6
  188.     tst.l    D0
  189.     beq.s    .port
  190.     move.l    IVEXTER(A6),D2
  191.     beq.w    .end
  192.     bra.s    .goon
  193. .port
  194.     move.l    IVPORTS(A6),D2
  195.     beq.w    .end
  196.  
  197. .goon
  198.     movea.l    D2,A2
  199.     move.l    (A2),D2            ; Server list
  200.     beq.w    .end
  201.     movea.l    D2,A2
  202.     move.l    14(A2),D2        ; Pointer to resource (ciax)
  203.     beq.w    .end
  204.     movea.l    D2,A2
  205.  
  206.     lea    64(A2),A2        ; ciax ICR vector 1 struct
  207.  
  208.     moveq    #0,D7            ; For ICR vectors 1 - 5
  209.  
  210. .scan
  211.     tst.w    D7            ; ICR vectors or interrupt?
  212.     beq.s    .firstset        ; If interrupt
  213.  
  214.     move.l    8(A2),D0        ; Pointer to interrupt node
  215.     beq.s    .next
  216.     movea.l    D0,A0
  217.  
  218.     moveq    #0,D0
  219.     move.b    D7,D0            ; ICR vector
  220.     subq.w    #1,D0
  221.     lsl.w    #1,D0            ; Compute table offset
  222.     lea    _ICRBit(pc),A1
  223.     move.w    0(A1,D0.w),D0        ; Offset to D0
  224.     pea    0(A1,D0.w)        ; Name of IRQ
  225.  
  226.     moveq    #0,D0
  227.     move.b    D7,D0
  228.     move.l    D0,-(sp)        ; ICR
  229.  
  230.     movea.l    LN_NAME(A0),A1
  231.     moveq    #-1,D0
  232. .strlen
  233.     tst.b    (A1)+
  234.     dbeq    D0,.strlen
  235.     not.l    D0
  236.     cmpi.b    #15,D0
  237.     bhi.s    .max
  238.     bra.s    .align
  239. .max
  240.     moveq    #16,D0
  241. .align
  242.     lea    _BlankTxt(pc),A1
  243.     lea    0(A1,D0.w),A1
  244.     move.l    A1,-(sp)
  245.  
  246.     move.l    LN_NAME(A0),-(sp)    ; Caller's name
  247.     moveq    #0,D0
  248.     move.b    LN_PRI(A0),D0
  249.     ext.w    D0
  250.     move.l    D0,-(sp)        ; PRI
  251.  
  252.     tst.b    D6
  253.     beq.s    .ciab
  254.     pea    _CIABTxt(pc)        ; CIA-B
  255.     bra.s    .textset
  256. .ciab
  257.     pea    _CIAATxt(pc)        ; CIA-A
  258. .textset
  259.     pea    _txt(pc)        ; Text
  260.     bsr.w    _printf
  261.     lea    28(sp),sp
  262.  
  263. .next
  264.     addq.w    #1,D7            ; Next Vector
  265.     cmpi.w    #5,D7            ; In range?
  266.     bhi.s    .end
  267.     lea    12(A2),A2        ; Next Interrupt vector structure
  268.     bra.s    .scan    
  269.  
  270. .firstset
  271.     move.l    A3,-(sp)
  272.     lea    -22(A2),A3
  273.  
  274. .stdscan
  275.     moveq    #1,D7            ; Set ICR vector
  276.     moveq    #0,D0
  277.     move.b    LN_PRI(A3),D0
  278.     ext.w    D0
  279.  
  280.     tst.w    D6            ; CIA-A or CIA-B?
  281.     beq.s    .CIAA
  282.  
  283.     lea    _CIABTxt(pc),A0        ; Level 6
  284.     bra.s    .set
  285. .CIAA
  286.     lea    _CIAATxt(pc),A0        ; Level 2
  287. .set
  288.     move.l    LN_NAME(A3),-(sp)    ; Name of interrupt
  289.     move.l    D0,-(sp)        ; Pri
  290.     move.l    A0,-(sp)        ; IRQ DES
  291.     pea    _CIAStdText(pc)
  292.     bsr.w    _printf
  293.     lea    16(sp),sp
  294.  
  295.     move.l    (A3),D0
  296.     beq.s    .nonext
  297.     movea.l    D0,A3
  298.     move.l    (A3),D0            ; Only end of node-list?
  299.     beq.s    .nonext
  300.     bra.s    .stdscan
  301. .nonext
  302.     movea.l    (sp)+,A3
  303.     bra.w    .scan
  304. .end
  305.     rts
  306.  
  307. *********************************************************
  308. * I'm waiting in this place where the sun never shines...
  309. * Stupid to write this function - it will never return
  310. * something meaningfull, when this task runs, no SoftInt
  311. * is running....
  312.  
  313. _GetSoftInts
  314.     movea.l    _SysBase(A5),A6
  315.     lea    SoftInts(A6),A3        ; Pointer to first list
  316.     moveq    #1,D2
  317.     moveq    #-32,D3
  318. .getnode
  319.     movea.l    A3,A2
  320.     move.l    (A2),D0            ; Pointer to first node
  321.     beq.s    .next
  322.     movea.l    D0,A2
  323.     move.l    (A2),D0            ; Only last entry?
  324.     beq.s    .done
  325. .loop
  326.     move.l    D3,-(sp)
  327.     move.l    LN_NAME(A2),-(sp)
  328.     pea    _SoftIntsTxt(pc)
  329.     bsr.w    _printf
  330.     lea    12(sp),sp
  331.  
  332.     move.l    (A2),D0
  333.     beq.s    .next
  334.     movea.l    D0,A2
  335.     move.l    (A2),D0            ; Only last entry?
  336.     bra.s    .loop
  337. .next
  338.     addq.w    #1,D2
  339.     cmpi.w    #5,D2
  340.     bhi.s    .done
  341.     addi.w    #16,D3
  342.     lea    SH_SIZE(A3),A3
  343.     bra.s    .getnode
  344. .done
  345.  
  346.     rts
  347.  
  348. ***************************************************************
  349. * Get Vector Base Reqister and from this the level 6 routine to
  350. * call level-6 interrupts.
  351.  
  352. _GetVBR
  353.     move.l    A5,-(sp)
  354.     movea.l    _SysBase(A5),A6
  355.     move.w    AttnFlags(A6),D0
  356.     lea    0.w,A0
  357.     andi.w    #AFF_68010!AFF_68020!AFF_68030!AFF_68040!AFF_68060,D0
  358.     beq.s    .na
  359.     lea    .except(pc),A5
  360.     jsr    _LVOSupervisor(A6)
  361.     movea.l    D0,A0    
  362. .na
  363.     move.l    $78(A0),D0        ; Level 6 ROM-code 
  364.     movea.l    (sp)+,A5
  365.     rts
  366.  
  367. .except
  368.     movec    VBR,D0
  369.     rte
  370.  
  371. ********************************************************************
  372. * Remember whithin 1 seconds all Cause() calls... a bit dangerous...
  373.  
  374. _SetPatch
  375.     pea    _PatchTxt(pc)
  376.     bsr.w    _printf
  377.     addq.l    #4,sp
  378.  
  379.     bsr.s    _SetFunction
  380.     move.l    _OldFunc(pc),D0
  381.     beq.s    .done
  382.  
  383.     moveq    #60,D1            ; ~1 second
  384.     movea.l    _DOSBase(A5),A6
  385.     jsr    _LVODelay(A6)
  386.  
  387.     bsr.s    _RemFunction
  388.  
  389.     move.l    _Entries(pc),D3
  390.     beq.s    .done
  391.  
  392.     lea    _CauseTable(pc),A3
  393. 1$
  394.     movea.l    (A3)+,A0
  395.     moveq    #0,D0
  396.     move.b    LN_PRI(A0),D0
  397.     ext.w    D0
  398.     move.l    D0,-(sp)
  399.     move.l    LN_NAME(A0),-(sp)
  400.     pea    _SoftIntsTxt(pc)
  401.     bsr.w    _printf
  402.     lea    12(sp),sp
  403.     subq.l    #1,D3
  404.     bne.s    1$
  405. .done
  406.     rts
  407.  
  408. _SetFunction
  409.     movea.l    _SysBase(A5),A6
  410.     jsr    _LVODisable(A6)
  411.     movea.l    A6,A1
  412.     lea    _LVOCause.w,A0
  413.     lea    _NewFunction(pc),A2
  414.     move.l    A2,D0
  415.     jsr    _LVOSetFunction(A6)
  416.     lea    _OldFunc(pc),A0
  417.     move.l    D0,(A0)
  418.     jsr    _LVOEnable(A6)
  419.     rts
  420.  
  421. _RemFunction
  422.     movea.l    _SysBase(A5),A6
  423.     jsr    _LVODisable(A6)
  424.     movea.l    A6,A1
  425.     lea    _LVOCause.w,A0
  426.     move.l    _OldFunc(pc),D0
  427.     jsr    _LVOSetFunction(A6)
  428.     jsr    _LVOEnable(A6)
  429.     rts
  430.  
  431. _NewFunction
  432.     lea    _CauseTable(pc),A0
  433. .loop
  434.     cmpa.l    (A0),A1            ; Else, compare raised one with those we remembered
  435.     beq.s    .alreadyset        ; If found...
  436.     tst.l    (A0)            ; Nothing remembered until now or a free entry in table?
  437.     beq.s    .setnew            ; Then set this irq
  438.     addq.l    #4,A0            ; Pointer to next remembered one or again a free entry
  439.     bra.s    .loop            ; Search on
  440.  
  441. .alreadyset
  442.     movea.l    _OldFunc(pc),A0        ; Was already remembered...
  443.     jmp    (A0)
  444.  
  445. .setnew                    ; Remember new one
  446.     move.l    _Entries(pc),D0    
  447.     cmpi.w    #(128/4)-3,D0        ; Entry buffer full?
  448.     bhi.s    .alreadyset
  449.  
  450.     move.l    A1,(A0)            ; If not, remember this irq
  451.     lea    _Entries(pc),A0
  452.     addq.l    #1,(A0)            ; Increase remember count
  453.     bra.s    .alreadyset        ; Call original exec function
  454.  
  455. _OldFunc
  456.     ds.l    1
  457. _Entries
  458.     ds.l    1
  459. _CauseTable
  460.     ds.b    128
  461.  
  462. ***********************************************************
  463. _PrintStatus
  464.     pea    _StatusTxt(pc)
  465.     bsr.w    _printf
  466.     addq.l    #4,sp
  467.     rts
  468. ***********************************************************
  469.  
  470.  
  471. _TBETxt
  472.     dc.b    'IRQ (TBEmpty Level 1), PRI %3d, owner: "%s',10,0
  473. _DSKBLKTxt
  474.     dc.b    'IRQ (DSKBLoK Level 1), PRI %3d, owner: "%s"',10,0
  475. _SOFTINTTxt
  476.     dc.b    'IRQ (SOFTINT Level 1), PRI %3d, owner: "%s"',10,0
  477. _COPTxt
  478.     dc.b    'IRQ (COPpER  Level 3), PRI %3d, owner: "%s"',10,0
  479. _VERTBTxt
  480.     dc.b    'IRQ (VERTB   Level 3), PRI %3d, owner: "%s"',10,0
  481. _BLITTxt
  482.     dc.b    'IRQ (BLITter Level 3), PRI %3d, owner: "%s"',10,0
  483. _AUD0Txt
  484.     dc.b    'IRQ (AUDio 0 Level 4), PRI %3d, owner: "%s"',10,0
  485. _AUD1Txt
  486.     dc.b    'IRQ (AUDio 1 Level 4), PRI %3d, owner: "%s"',10,0
  487. _AUD2Txt
  488.     dc.b    'IRQ (AUDio 2 Level 4), PRI %3d, owner: "%s"',10,0
  489. _AUD3Txt
  490.     dc.b    'IRQ (AUDio 3 Level 4), PRI %3d, owner: "%s"',10,0
  491. _RBFTxt
  492.     dc.b    'IRQ (RBFull  Level 5), PRI %3d, owner: "%s"',10,0
  493. _DSKSYNTxt
  494.     dc.b    'IRQ (DSKSYNC Level 5), PRI %3d, owner: "%s"',10,0
  495. _SoftIntsTxt
  496.     dc.b    'IRQ (SOFTINTS Level 1) raised by: "%s", PRI: %d',10,0
  497. _LF
  498.     dc.b    10,0
  499. _BlankTxt
  500.     dc.b    '                '
  501.     dc.b    0
  502. _txt
  503.     dc.b    'IRQ %s, PRI %3d, owner: "%s",%s IVEC %d = %s',10,0
  504. _CIAStdText
  505.     dc.b    'IRQ %s, PRI %3d, owner: "%s"',10,0
  506. _CIAATxt
  507.     dc.b    '(PORTS   Level 2)',0
  508. _CIABTxt
  509.     dc.b    '(EXTER   Level 6)',0
  510. _StatusTxt
  511.     dc.b    'IntList V3.0 - Based on noone''s Guru''s Guide',10
  512.     dc.b    '- Copyright 1996  ONIX - Exec should be rewritten...',10,10,0
  513. _PatchTxt
  514.     dc.b    10,'Scanning for Cause() Level 1 interrupts',10
  515.     dc.b    'Hold on, computing for about one second...',10,10,0
  516. _VerTxt
  517.     dc.b    '$VER: IntList 3.14 (08.11.97) Copyright J.v.d.Loo »ONIX«',13,10,0
  518.  
  519.     CNOP    0,4
  520. _ICRBit
  521.     dc.w    1$-_ICRBit
  522.     dc.w    2$-_ICRBit
  523.     dc.w    3$-_ICRBit
  524.     dc.w    4$-_ICRBit
  525.     dc.w    5$-_ICRBit
  526. 1$
  527.     dc.b    'Timer A    ',0
  528. 2$
  529.     dc.b    'Timer B    ',0
  530. 3$
  531.     dc.b    'TOD Alarm  ',0
  532. 4$
  533.     dc.b    'Serial Port',0
  534. 5$
  535.     dc.b    'Flag Input ',0
  536.  
  537.  
  538.     CNOP    0,4
  539.  
  540. *********************************************************************************
  541. *
  542. ** Dies ist die printf()-Routine mit gleichgebliebenen Syntax wie die originale!
  543. ** C spezifische Argumente werden aber nicht verwaltet, so z.B. "%#8ld" oder
  544. ** dergleichen, da die eigentliche Arbeit an RawDoFmt() übergeben wird, und diese
  545. ** Betriebssystemroutine dies nicht unterstützt.
  546. *
  547. ** Falls jemand seine eigenen Routinen für den MC++-Compiler der Version 1.10.7
  548. ** schreiben möchte, so muß er tunlichst darauf achten das Prozessor-Register
  549. ** A6 instand zu halten. Dieses Register wird intern verwendet, so z.B. im Opti=
  550. ** mierungsmodus.
  551. *
  552.  
  553.     OPT    OW-
  554.  
  555. pfBufferSize    EQU    256
  556.  
  557.      STRUCTURE    printfBuf,0
  558.     STRUCT    _pfCnt,4        ; Zähler für Anzahl Buchstaben
  559.     STRUCT    _pfBuffer,pfBufferSize    ; Platz für eine Zeile von 127 Bytes
  560.     LABEL    _pfArgs            ; Dynamische Größe...
  561.     LABEL    pfb_SIZE        ; Bestimmt nicht das Strukturende.....
  562.  
  563.  
  564. _printf
  565.     movem.l    D2-D5/A2-A3/A6,-(sp)    ; Alle benötigten Register retten
  566.     movea.l    32(sp),A0        ; Zeiger auf den zu formatierenden Text
  567.     moveq    #-1,D1            ; Dummy-Zähler
  568.     moveq    #0,D0            ; Zähler für Argumente
  569. 0$
  570.     cmpi.b    #'%',(A0)        ; Argument?
  571.     bne.s    .NoArg            ; Nö...
  572.     addq.w    #1,D0            ; Argument +1
  573. .NoArg
  574.     tst.b    (A0)+            ; Ende der Zeichenkette?
  575.     dbeq    D1,0$            ; Wenn nicht...
  576.  
  577.     lsl.l    #2,D0            ; Anzahl Argumente mal 4 ( Langworte )
  578.     add.l    #pfb_SIZE,D0        ; 4 Bytes für Zähler, rest Puffer
  579.     addq.l    #7,D0
  580.     andi.l    #-8,D0            ; Durch acht teilbar machen
  581.     move.l    D0,D5            ; Größe sichern
  582.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,D1 ; Anforderungen an den Speicher
  583.     movea.l    _SysBase(A5),A6
  584.     jsr    _LVOAllocMem(A6)    ; Speicher anfordern
  585.     move.l    D0,D4            ; Adresse Speicher
  586.     beq.s    3$            ; Falls Fehler...
  587.  
  588.     movea.l    32(sp),A0        ; Zeiger auf unformatierte Zeichenkette
  589.     lea    36(sp),A1        ; Zeiger auf die Argumentenliste
  590.     movea.l    D4,A2            ; Adresse Tabelle
  591.     lea    _pfArgs(A2),A2        ; Adresse Argumenten-Puffer (ab Offset 132)
  592.  
  593.     moveq    #-1,D1            ; Dummy-Zähler als Anweisung für
  594.     bra.s    1$            ; Turbo-Boards
  595.  
  596. * --    #############  -- *
  597. .skip
  598.     addq.l    #2,A0            ; Beide %-Zeichen überlesen
  599.     subq.w    #2,D1            ; 2 Zeichen weniger im Text
  600.     bmi.s    3$            ; Falls Fehler (Übertrag)
  601.  
  602. * --- Hier gehts los! --- *
  603. 1$
  604.     cmpi.b    #'%',(A0)        ; Argument?
  605.     bne.s    2$            ; Nee...
  606.     cmpi.b    #'%',1(A0)        ; oder nur ein Prozentzeichen ausgeben?
  607.     beq.s    .skip            ; wenn so, beide %-Zeichen überlesen
  608.     addq.l    #1,A0            ; Sonst nur ein %-Zeichen überlesen
  609.     subq.w    #1,D1            ; Zähler dekremieren
  610. .getType
  611.     cmpi.b    #'b',(A0)        ; Argument = BCPL?
  612.     beq.s    .typeFound        ; wenn so...
  613.     cmpi.b    #'d',(A0)        ; Dezimal-Zahl?
  614.     beq.s    .typeFound.1
  615.     cmpi.b    #'x',(A0)        ; Sedezimale Zahl?
  616.     beq.s    .typeFound.1
  617.     cmpi.b    #'s',(A0)        ; Zeichenkette?
  618.     beq.s    .typeFound
  619.     cmpi.b    #'c',(A0)        ; Ein Buchstaben (o. Zahl)?
  620.     beq.s    .typeFound.1
  621. *
  622. ** Da ein Argument so aufgebaut sein kann: '%08ld' suchen wir nur nach der
  623. ** gültigen Beschreibung für das Argument, hier 'd' in einer Schleife.
  624. *
  625.     tst.b    (A0)+            ; Loop-Anweisung
  626.     dbeq    D1,.getType        ; und weiter machen, solange nicht
  627. *                      gefunden
  628.     bra.s    3$            ; Wenn Fehler (Ende des Strings ohne
  629. *                      Argument!)
  630. .typeFound.1
  631.     cmp.b    #'l',-1(A0)        ; Langwort?
  632.     beq.s    .typeFound        ; dann andere Routine
  633.     move.l    (A1),D0            ; Hole Argument (immer ein Langwort!)
  634.     move.w    D0,(A2)+        ; Schreibe für Exec aber nur Wort!
  635.     addq.l    #4,A1            ; Zeiger auf nachfolgenden Parameter
  636. *                      (Argumenten-Inhalt)
  637.     bra.s    2$            ; und normal weiter machen
  638. .typeFound
  639.     move.l    (A1),(A2)+        ; Argumenten-Inhalt in den Puffer
  640.     addq.l    #4,A1            ; siehe oben
  641. 2$
  642.     tst.b    (A0)+            ; Suche NULL-Byte
  643.     dbeq    D1,1$
  644.     bra.s    .FmtString        ; == Ende der Zeichenkette, jetzt die
  645. *                      Zeichenkette ausgeben
  646. 3$
  647.     moveq    #-1,D0            ; Fehler retournieren
  648. .printf_end
  649.     tst.l    D4            ; Adresse Tabelle?
  650.     beq.s    4$
  651.     movea.l    D4,A1            ; Adresse Tabelle!
  652.     move.l    D5,D0            ; Größe Tabelle
  653.     movea.l    _SysBase(A5),A6
  654.     jsr    _LVOFreeMem(A6)        ; Tabelle freigeben
  655. 4$
  656.     movem.l    (sp)+,D2-D5/A2-A3/A6
  657.     rts
  658.  
  659.  
  660. .FmtString
  661.     movea.l    32(sp),A0        ; Zeiger auf unformatierte Zeichnekette
  662.     movea.l    D4,A3            ; Adresse Tabelle
  663.     lea    _pfArgs(A3),A1        ; Adresse Argumenten-Puffer nach A1 (Stream)
  664.     lea    .Hook(pc),A2        ; Call-Back-Routine
  665. *    movea.l    A3,A3            ; Adresse Tabelle sowieso in A3
  666.     movea.l    _SysBase(A5),A6        ; Basis Exec
  667.     jsr    _LVORawDoFmt(A6)    ; Zeichenkette formatieren
  668.     move.l    _stdout(A5),D1        ; MC++'s Output-Handle
  669.     beq.s    3$            ; falls Fehler (nicht vorhanden)
  670.     movea.l    D4,A0            ; Tabelle
  671.     lea    _pfBuffer(A0),A1    ; Adresse formatierter Text im Puffer
  672.     move.l    A1,D2            ; nach D2
  673.     move.l    _pfCnt(A0),D3        ; Länge des Text
  674.     beq.s    .okEnd            ; Falls Zeichenkette schon ausgegeben wurde...
  675.     subq.l    #1,D3            ; Ignoriere null-Byte am Ende der Zeichenkette
  676.     beq.s    .okEnd            ; Falls null
  677.     movea.l    _DOSBase(A5),A6        ; Basis DOS
  678.     jsr    _LVOWrite(A6)        ; Text schreiben (in Konsole)
  679. .okEnd
  680.     moveq    #0,D0            ; Kein Fehler
  681.     bra.s    .printf_end
  682.  
  683.  
  684. .Hook
  685. * D0 == Buchstaben, wird retourniert von RawDoFmt()
  686. * A3 == Zeiger auf Tabelle, wird retourniert von RawDoFmt()
  687.     movem.l    D1/A0,-(sp)
  688.     lea    _pfBuffer(A3),A0    ; Puffer für formatierten Text
  689.     move.l    _pfCnt(A3),D1        ; Anzahl Zeichen die schon im Puffer
  690. *                      abgelegt worden sind
  691.     move.b    D0,0(A0,D1.w)        ; aktuelles Zeichen dranhängen
  692.     addq.l    #1,_pfCnt(A3)        ; Zähler inkrementieren
  693.     cmpi.l    #pfBufferSize-2,D1    ; Maximale Anzahl Zeichen im Puffer!?
  694.     bls.s    .ok            ; Wenn weniger o. gleich, ok.
  695.  
  696.     clr.b    -1(A0,D1.w)
  697.     subq.l    #1,_pfCnt(A3)
  698.  
  699. .ok    
  700.     movem.l    (sp)+,D1/A0
  701.     rts
  702.  
  703.     OPT    OW+
  704.  
  705.  
  706.     END
  707.